package com.googlecode.bip.xml.export;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;

/**
 * Handle XML export from MySQL database
 */
//not public
class XMLSurvey implements XMLAppender
{
  private static final long serialVersionUID = 1L;
  private List<XMLTopic>    topicList;
  private List<XMLQuestion> questionList;

  public XMLSurvey( XMLSurveyConnection connection )
      throws SQLException, NamingException
  {
      topicList    = XMLTopicFactory.createList( connection, 0 );
      questionList = XMLQuestionFactory.createList( connection, 0 );
  }

  /**
   * <XMP>
   * <!ELEMENT survey        (topic*,question*)>
   * </XMP>
   */
  @Override
  public void appendXML( Appendable a ) throws IOException
  {
      a.append( "<survey>\n" );

      XMLAppenderHelper.appendXML( a, topicList );
      XMLAppenderHelper.appendXML( a, questionList );

      a.append( "</survey>\n" );
  }

}
